package com.ruoyi.web.controller.warehouse;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.domain.WareHouseTank;
import com.ruoyi.warehouse.service.IWareHouseTankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库中心=>鱼缸Controller
 * 
 * @author 杨彬鑫
 * @date 2021-01-29
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/warehouse/tank" )
public class TankController extends BaseController {

    private final IWareHouseTankService iWareHouseTankService;

    /**
     * 查询仓库中心=>鱼缸列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:list')")
    @GetMapping("/list")
    public TableDataInfo list(WareHouseTank wareHouseTank) {
        startPage();
        List<WareHouseTank> list = iWareHouseTankService.queryList(wareHouseTank);
        return getDataTable(list);
    }

    /**
     * 导出仓库中心=>鱼缸列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:export')" )
    @Log(title = "仓库中心=>鱼缸" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(WareHouseTank wareHouseTank) {
        List<WareHouseTank> list = iWareHouseTankService.queryList(wareHouseTank);
        ExcelUtil<WareHouseTank> util = new ExcelUtil<WareHouseTank>(WareHouseTank.class);
        return util.exportExcel(list, "tank" );
    }

    /**
     * 获取仓库中心=>鱼缸详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:query')" )
    @GetMapping(value = "/{tankCode}" )
    public AjaxResult getInfo(@PathVariable("tankCode" ) String tankCode) {
        return AjaxResult.success(iWareHouseTankService.getById(tankCode));
    }

    /**
     * 新增仓库中心=>鱼缸
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:add')" )
    @Log(title = "仓库中心=>鱼缸" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WareHouseTank wareHouseTank) {
        return toAjax(iWareHouseTankService.save(wareHouseTank) ? 1 : 0);
    }

    /**
     * 修改仓库中心=>鱼缸
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:edit')" )
    @Log(title = "仓库中心=>鱼缸" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WareHouseTank wareHouseTank) {
        return toAjax(iWareHouseTankService.updateById(wareHouseTank) ? 1 : 0);
    }

    /**
     * 删除仓库中心=>鱼缸
     */
    @PreAuthorize("@ss.hasPermi('warehouse:tank:remove')" )
    @Log(title = "仓库中心=>鱼缸" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{tankCodes}" )
    public AjaxResult remove(@PathVariable String[] tankCodes) {
        return toAjax(iWareHouseTankService.removeByIds(Arrays.asList(tankCodes)) ? 1 : 0);
    }
}
